package com.example.flowabledemo.listener;

import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.common.engine.api.delegate.event.FlowableEventType;

import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.JOB_EXECUTION_FAILURE;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.JOB_EXECUTION_SUCCESS;

/**
 * @author xlang
 * @version 0.0.1
 * @desciption
 * @date 2021/8/2 15:18
 */
public class FlowableListener implements FlowableEventListener {
    @Override
    public void onEvent(FlowableEvent event) {

        FlowableEventType type = event.getType();
        if (JOB_EXECUTION_SUCCESS.equals(type)) {
            System.out.println("A job well done!");
        } else if (JOB_EXECUTION_FAILURE.equals(type)) {
            System.out.println("A job has failed...");
        } else {//语句
            System.out.println("Flowable received: " + event.getType());
        }
    }

    /**
     * 若返回false，忽略异常；
     * 若返回true，异常不会被忽略而会被上抛，使当前执行的命令失败
     */
    @Override
    public boolean isFailOnException() {
        return false;
    }

    @Override
    public boolean isFireOnTransactionLifecycleEvent() {
        return false;
    }

    @Override
    public String getOnTransaction() {
        return null;
    }
}
